/**
 * Created by sunny.w <iwisunny@gmail.com> on 15-7-30.
 */
(function(g){

    wxi.shopBundle.registerEditor($('#ueditor'), 'ueditor', function(ue){
        //将editor内容与textarea保持一致
        var cont=$('#brand_desc').html();
        ue.setContent(wxi.string.htmlEncode(cont));
    });

    $('#btn_submit_form').on('click',function(){
        var fm=$(this).parents('form');
        var logo=$('#brand_logo');

        var entity=wxi.shopBundle.
            preCheckForm(fm, 'shop_adminbundle_brand');

        entity.description=UE.getEditor('ueditor').getContent();

        //console.log(entity);
        //console.log(fm.serialize());

        if(!entity.name){
            wxi.util.tipMsg('', '请填写品牌名');
            return false;
        }

        if(!entity.description){
            wxi.util.tipMsg('', '请填写品牌描述');
            return false;
        }
        else{
            fm.find('#brand_desc').html(entity.description);
        }

        if(!logo.prev().hasClass('img-container')){
            //new brand page
            if(!logo.val()){
                wxi.util.tipMsg('', '请上传品牌图片');
                return false;
            }
        }

        fm.submit();

    });



})(this);
